//
//  GJTabBarController.m
//  HaoHaiSpell
//
//  Created by 郭健 on 16/6/14.
//  Copyright © 2016年 海城. All rights reserved.
//

#import "GJTabBarController.h"
#import "HomepageViewController.h"
#include "HotController.h"
#import "SpellViewController.h"
<<<<<<< HEAD
#import "ShopController.h"
=======
#import "ClassificationViewController.h"
>>>>>>> 5bee59541ff07dbcbaa6fe419e6df24b39c5e23d
#import "PersonalController.h"


#import "GJNavController.h"

@interface GJTabBarController ()

@end

@implementation GJTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setupChildViewControllers];
}

-(void)setupChildViewControllers{

    HomepageViewController *indexVC  = [[HomepageViewController alloc]init];
    [self childViewController:indexVC imageName:@"ico_index1" selectedImageName:@"ico_index2" withTitle:@"首页"];
    
    SpellViewController *spellVC = [[SpellViewController alloc]init];
    [self childViewController:spellVC imageName:@"ico_tuan1" selectedImageName:@"ico_tuan2" withTitle:@"拼团"];
    
<<<<<<< HEAD
    ShopController *shopVC = [[ShopController alloc]init];
=======
    ClassificationViewController *shopVC = [[ClassificationViewController alloc]init];
>>>>>>> 5bee59541ff07dbcbaa6fe419e6df24b39c5e23d
    [self childViewController:shopVC imageName:@"ico_mall1" selectedImageName:@"ico_mall2" withTitle:@"商城"];
    
    HotController *hotVC = [[HotController alloc]init];
    [self childViewController:hotVC imageName:@"ico_square1" selectedImageName:@"ico_square2" withTitle:@"广场"];
    
    PersonalController *personalVC = [[PersonalController alloc]init];
    [self childViewController:personalVC imageName:@"ico_user1" selectedImageName:@"ico_user2" withTitle:@"个人中心"];
    
    
}

- (void)childViewController:(UIViewController *)vc imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName withTitle:(NSString *)title
{
//    UINavigationController * nav = [[UINavigationController alloc] initWithRootViewController:vc];
//    nav.tabBarItem.image = [UIImage imageNamed:imageName];
//    nav.tabBarItem.selectedImage = [UIImage imageNamed:selectedImageName];
//    nav.tabBarItem.title = title;
//    [self addChildViewController:nav];
    
    // 设置子控制器的文字
    vc.title = title; // 同时设置tabbar和navigationBar的文字
    vc.tabBarItem.title = title; // 设置tabbar的文字
        vc.navigationItem.title = title; // 设置navigationBar的文字
    
    // 设置子控制器的图片
    vc.tabBarItem.image = [[UIImage imageNamed:imageName] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    vc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImageName]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

    // 设置文字的样式
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = HWColor(123, 123, 123);
    NSMutableDictionary *selectTextAttrs = [NSMutableDictionary dictionary];
    selectTextAttrs[NSForegroundColorAttributeName] = [UIColor redColor];
    [vc.tabBarItem setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
    [vc.tabBarItem setTitleTextAttributes:selectTextAttrs forState:UIControlStateSelected];
    //childVc.view.backgroundColor = HWRandomColor;
    
    // 先给外面传进来的小控制器 包装 一个导航控制器
    GJNavController *nav = [[GJNavController alloc] initWithRootViewController:vc];
    // 添加为子控制器
    [self addChildViewController:nav];
}



















- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
